<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width">
<meta name="theme-color" content="#222"><meta name="generator" content="Hexo 7.3.0">

  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32.ico">
  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16.ico">
  <link rel="mask-icon" href="/images/logo.svg" color="#222">

<link rel="stylesheet" href="/css/main.css">



<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.1/css/all.min.css" integrity="sha256-wiz7ZSCn/btzhjKDQBms9Hx4sSeUYsDrTLg7roPstac=" crossorigin="anonymous">
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/animate.css/3.1.1/animate.min.css" integrity="sha256-PR7ttpcvz8qrF57fur/yAx1qXMFJeJFiA6pSzWi0OIE=" crossorigin="anonymous">
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/fancyapps-ui/5.0.28/fancybox/fancybox.css" integrity="sha256-6cQIC71/iBIYXFK+0RHAvwmjwWzkWd+r7v/BX3/vZDc=" crossorigin="anonymous">
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/pace/1.2.4/themes/green/pace-theme-minimal.css">
  <script src="https://cdnjs.cloudflare.com/ajax/libs/pace/1.2.4/pace.min.js" integrity="sha256-gqd7YTjg/BtfqWSwsJOvndl0Bxc8gFImLEkXQT8+qj0=" crossorigin="anonymous"></script>

<script class="next-config" data-name="main" type="application/json">{"hostname":"sumumm.github.io","root":"/","images":"/images","scheme":"Gemini","darkmode":false,"version":"8.19.2","exturl":false,"sidebar":{"position":"left","display":"post","padding":18,"offset":12},"copycode":{"enable":true,"style":"mac"},"fold":{"enable":true,"height":300},"bookmark":{"enable":false,"color":"#222","save":"auto"},"mediumzoom":false,"lazyload":true,"pangu":false,"comments":{"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},"stickytabs":false,"motion":{"enable":true,"async":true,"transition":{"menu_item":"fadeInDown","post_block":"fadeIn","post_header":"fadeInDown","post_body":"fadeInDown","coll_header":"fadeInLeft","sidebar":"fadeInUp"}},"i18n":{"placeholder":"搜索...","empty":"没有找到任何搜索结果：${query}","hits_time":"找到 ${hits} 个搜索结果（用时 ${time} 毫秒）","hits":"找到 ${hits} 个搜索结果"},"path":"/search.xml","localsearch":{"enable":true,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":false}}</script><script src="/js/config.js"></script>

    <meta name="description" content="GitHub Actions的工作流程怎么写？语法是怎样的？若笔记中有错误或者不合适的地方，欢迎批评指正😃。">
<meta property="og:type" content="article">
<meta property="og:title" content="LV02-GitHubActions-02-工作流程语法">
<meta property="og:url" content="https://sumumm.github.io/post/6476912c.html">
<meta property="og:site_name" content="苏木">
<meta property="og:description" content="GitHub Actions的工作流程怎么写？语法是怎样的？若笔记中有错误或者不合适的地方，欢迎批评指正😃。">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/02%E5%BC%80%E5%8F%91%E5%B7%A5%E5%85%B7/05GithubActions/LV02-GitHubActions-02-%E5%B7%A5%E4%BD%9C%E6%B5%81%E7%A8%8B%E8%AF%AD%E6%B3%95/img/image-20241227161703506.png">
<meta property="article:published_time" content="2024-12-28T01:54:59.000Z">
<meta property="article:modified_time" content="2025-06-13T16:25:57.072Z">
<meta property="article:author" content="苏木">
<meta property="article:tag" content="GithubActions">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/02%E5%BC%80%E5%8F%91%E5%B7%A5%E5%85%B7/05GithubActions/LV02-GitHubActions-02-%E5%B7%A5%E4%BD%9C%E6%B5%81%E7%A8%8B%E8%AF%AD%E6%B3%95/img/image-20241227161703506.png">


<link rel="canonical" href="https://sumumm.github.io/post/6476912c.html">



<script class="next-config" data-name="page" type="application/json">{"sidebar":"","isHome":false,"isPost":true,"lang":"zh-CN","comments":"","permalink":"https://sumumm.github.io/post/6476912c.html","path":"post/6476912c.html","title":"LV02-GitHubActions-02-工作流程语法"}</script>

<script class="next-config" data-name="calendar" type="application/json">""</script>
<title>LV02-GitHubActions-02-工作流程语法 | 苏木</title>
  








    <script src="/js/browser_tools_disable.js"></script>

  <noscript>
    <link rel="stylesheet" href="/css/noscript.css">
  </noscript>
<!-- hexo injector head_end start --><link rel="stylesheet" href="https://unpkg.com/hexo-next-tags-plus@latest/lib/tag_plus.css" media="defer" onload="this.media='all'"><!-- hexo injector head_end end --></head>

<body itemscope itemtype="http://schema.org/WebPage" class="use-motion">
  <div class="headband"></div>

  <main class="main">
    <div class="column">
      <header class="header" itemscope itemtype="http://schema.org/WPHeader"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="切换导航栏" role="button">
        <span class="toggle-line"></span>
        <span class="toggle-line"></span>
        <span class="toggle-line"></span>
    </div>
  </div>

  <div class="site-meta">

    <a href="/" class="brand" rel="start">
      <i class="logo-line"></i>
      <p class="site-title">苏木</p>
      <i class="logo-line"></i>
    </a>
      <p class="site-subtitle" itemprop="description">我的学习之路</p>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger" aria-label="搜索" role="button">
        <i class="fa fa-search fa-fw fa-lg"></i>
    </div>
  </div>
</div>



<nav class="site-nav">
  <ul class="main-menu menu"><li class="menu-item menu-item-home"><a href="/" rel="section"><i class="fa fa-home fa-fw"></i>苏木的家</a></li><li class="menu-item menu-item-categories"><a href="/categories/" rel="section"><i class="fa fa-th fa-fw"></i>分类页<span class="badge">42</span></a></li><li class="menu-item menu-item-archives"><a href="/archives/" rel="section"><i class="fa fa-archive fa-fw"></i>归档页<span class="badge">673</span></a></li><li class="menu-item menu-item-flink"><a href="/flink/" rel="section"><i class="fa fa-link fa-fw"></i>友人帐</a></li><li class="menu-item menu-item-about"><a href="/about/" rel="section"><i class="fa fa-user fa-fw"></i>关于我</a></li>
      <li class="menu-item menu-item-search">
        <a role="button" class="popup-trigger"><i class="fa fa-search fa-fw"></i>搜索
        </a>
      </li>
  </ul>
</nav>



  <div class="search-pop-overlay">
    <div class="popup search-popup"><div class="search-header">
  <span class="search-icon">
    <i class="fa fa-search"></i>
  </span>
  <div class="search-input-container">
    <input autocomplete="off" autocapitalize="off" maxlength="80"
           placeholder="搜索..." spellcheck="false"
           type="search" class="search-input">
  </div>
  <span class="popup-btn-close" role="button">
    <i class="fa fa-times-circle"></i>
  </span>
</div>
<div class="search-result-container no-result">
  <div class="search-result-icon">
    <i class="fa fa-spinner fa-pulse fa-5x"></i>
  </div>
</div>

    </div>
  </div>

</header>
        
  
  <aside class="sidebar">

    <div class="sidebar-inner sidebar-nav-active sidebar-toc-active">
      <ul class="sidebar-nav">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <div class="sidebar-panel-container">
        <!--noindex-->
        <div class="post-toc-wrap sidebar-panel">
            <div class="post-toc animated"><ol class="nav"><li class="nav-item nav-level-1"><a class="nav-link" href="#%E4%B8%80%E3%80%81%E5%9F%BA%E6%9C%AC%E6%A6%82%E5%BF%B5"><span class="nav-text">一、基本概念</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#1-%E5%9F%BA%E6%9C%AC%E6%9C%AF%E8%AF%AD"><span class="nav-text">1. 基本术语</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#2-workflow-%E6%96%87%E4%BB%B6"><span class="nav-text">2. workflow 文件</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#3-%E4%B8%8A%E4%B8%8B%E6%96%87"><span class="nav-text">3. 上下文</span></a></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#%E4%BA%8C%E3%80%81%E5%B7%A5%E4%BD%9C%E6%B5%81%E8%AF%AD%E6%B3%95"><span class="nav-text">二、工作流语法</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#1-name"><span class="nav-text">1. name</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#2-run-name"><span class="nav-text">2. run-name</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#3-on"><span class="nav-text">3. on</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#3-1-%E4%BD%BF%E7%94%A8%E5%8D%95%E4%B8%AA%E4%BA%8B%E4%BB%B6"><span class="nav-text">3.1 使用单个事件</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#3-2-%E4%BD%BF%E7%94%A8%E6%B4%BB%E5%8A%A8%E7%B1%BB%E5%9E%8B"><span class="nav-text">3.2 使用活动类型</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#3-3-%E4%BD%BF%E7%94%A8%E8%BF%87%E6%BB%A4%E5%99%A8"><span class="nav-text">3.3 使用过滤器</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#3-4-%E7%BB%93%E5%90%88%E4%BD%BF%E7%94%A8%E6%B4%BB%E5%8A%A8%E7%B1%BB%E5%9E%8B%E5%92%8C%E8%BF%87%E6%BB%A4%E5%99%A8%E4%BB%A5%E5%8F%8A%E5%A4%9A%E4%B8%AA%E4%BA%8B%E4%BB%B6"><span class="nav-text">3.4 结合使用活动类型和过滤器以及多个事件</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#3-5-%E6%80%BB%E7%BB%93"><span class="nav-text">3.5 总结</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#4-jobs"><span class="nav-text">4. jobs</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#4-1-jobs-needs"><span class="nav-text">4.1 jobs..needs</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#4-1-1-%E8%AF%AD%E6%B3%95%E8%AF%B4%E6%98%8E"><span class="nav-text">4.1.1 语法说明</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#4-1-2-%E7%A4%BA%E4%BE%8B%EF%BC%9A%E9%9C%80%E8%A6%81%E6%88%90%E5%8A%9F%E7%9A%84%E4%BE%9D%E8%B5%96%E4%BD%9C%E4%B8%9A"><span class="nav-text">4.1.2 示例：需要成功的依赖作业</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#4-1-3-%E7%A4%BA%E4%BE%8B%EF%BC%9A%E4%B8%8D%E9%9C%80%E8%A6%81%E6%88%90%E5%8A%9F%E7%9A%84%E4%BE%9D%E8%B5%96%E4%BD%9C%E4%B8%9A"><span class="nav-text">4.1.3 示例：不需要成功的依赖作业</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#4-2-jobs-runs-on"><span class="nav-text">4.2 jobs..runs-on</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#4-2-1-%E8%AF%AD%E6%B3%95%E8%AF%B4%E6%98%8E"><span class="nav-text">4.2.1 语法说明</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#4-2-2-%E9%80%89%E6%8B%A9-GitHub-%E6%89%98%E7%AE%A1%E8%BF%90%E8%A1%8C%E5%99%A8"><span class="nav-text">4.2.2 选择 GitHub 托管运行器</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#4-2-3-%E9%80%89%E6%8B%A9%E8%87%AA%E6%89%98%E7%AE%A1%E8%BF%90%E8%A1%8C%E5%99%A8"><span class="nav-text">4.2.3 选择自托管运行器</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#4-3-jobs-if"><span class="nav-text">4.3 jobs..if</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#4-3-1-%E8%AF%AD%E6%B3%95%E8%AF%B4%E6%98%8E"><span class="nav-text">4.3.1 语法说明</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#4-3-2-%E7%A4%BA%E4%BE%8B%EF%BC%9A%E4%BB%85%E4%B8%BA%E7%89%B9%E5%AE%9A%E5%AD%98%E5%82%A8%E5%BA%93%E8%BF%90%E8%A1%8C%E4%BD%9C%E4%B8%9A"><span class="nav-text">4.3.2 示例：仅为特定存储库运行作业</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#4-3-3-%E7%A4%BA%E4%BE%8B%EF%BC%9A%E4%BB%85%E4%B8%BA%E7%89%B9%E5%AE%9Atag%E5%88%9B%E5%BB%BA%E6%97%B6%E8%BF%90%E8%A1%8C%E4%BD%9C%E4%B8%9A"><span class="nav-text">4.3.3 示例：仅为特定tag创建时运行作业</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#4-4-jobs-steps"><span class="nav-text">4.4 jobs..steps</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#4-4-1-%E8%AF%AD%E6%B3%95%E8%AF%B4%E6%98%8E"><span class="nav-text">4.4.1 语法说明</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#4-4-2-jobs-steps%E7%A4%BA%E4%BE%8B"><span class="nav-text">4.4.2 jobs..steps示例</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#4-5-jobs-steps-uses"><span class="nav-text">4.5 jobs..steps..uses</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#4-5-1-%E8%AF%AD%E6%B3%95%E8%AF%B4%E6%98%8E"><span class="nav-text">4.5.1 语法说明</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#4-5-2-%E7%A4%BA%E4%BE%8B%EF%BC%9A%E4%BD%BF%E7%94%A8%E7%89%88%E6%9C%AC%E5%8C%96%E7%9A%84%E6%93%8D%E4%BD%9C"><span class="nav-text">4.5.2 示例：使用版本化的操作</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#4-5-3-%E7%A4%BA%E4%BE%8B%EF%BC%9A%E4%BD%BF%E7%94%A8%E5%85%AC%E5%85%B1%E6%93%8D%E4%BD%9C"><span class="nav-text">4.5.3 示例：使用公共操作</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#4-5-4-%E7%A4%BA%E4%BE%8B%EF%BC%9A%E5%9C%A8%E5%AD%90%E7%9B%AE%E5%BD%95%E4%B8%AD%E4%BD%BF%E7%94%A8%E5%85%AC%E5%85%B1%E6%93%8D%E4%BD%9C"><span class="nav-text">4.5.4 示例：在子目录中使用公共操作</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#4-5-5-%E7%A4%BA%E4%BE%8B%EF%BC%9A%E5%9C%A8%E4%B8%8E%E5%B7%A5%E4%BD%9C%E6%B5%81%E7%9B%B8%E5%90%8C%E7%9A%84%E4%BB%93%E5%BA%93%E4%B8%AD%E4%BD%BF%E7%94%A8%E6%93%8D%E4%BD%9C"><span class="nav-text">4.5.5 示例：在与工作流相同的仓库中使用操作</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#4-5-6-%E7%A4%BA%E4%BE%8B%EF%BC%9A%E4%BD%BF%E7%94%A8-Docker-Hub-%E6%93%8D%E4%BD%9C"><span class="nav-text">4.5.6 示例：使用 Docker Hub 操作</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#4-5-7-%E7%A4%BA%E4%BE%8B%EF%BC%9A%E4%BD%BF%E7%94%A8-GitHub-Packages-%E5%AE%B9%E5%99%A8%E6%B3%A8%E5%86%8C%E8%A1%A8"><span class="nav-text">4.5.7 示例：使用 GitHub Packages 容器注册表</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#4-5-8-%E7%A4%BA%E4%BE%8B%EF%BC%9A%E4%BD%BF%E7%94%A8-Docker-%E5%85%AC%E5%85%B1%E6%B3%A8%E5%86%8C%E8%A1%A8%E6%93%8D%E4%BD%9C"><span class="nav-text">4.5.8 示例：使用 Docker 公共注册表操作</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#4-5-9-%E7%A4%BA%E4%BE%8B%EF%BC%9A%E5%9C%A8%E4%B8%8E%E5%B7%A5%E4%BD%9C%E6%B5%81%E4%B8%8D%E5%90%8C%E7%9A%84%E7%A7%81%E6%9C%89%E4%BB%93%E5%BA%93%E4%B8%AD%E4%BD%BF%E7%94%A8%E6%93%8D%E4%BD%9C"><span class="nav-text">4.5.9 示例：在与工作流不同的私有仓库中使用操作</span></a></li></ol></li></ol></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#%E4%B8%89%E3%80%81%E5%B8%B8%E7%94%A8%E5%85%AC%E5%85%B1actions"><span class="nav-text">三、常用公共actions</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#1-actions-checkout"><span class="nav-text">1. actions&#x2F;checkout</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#2-softprops-action-gh-release"><span class="nav-text">2.  softprops&#x2F;action-gh-release</span></a></li></ol></li></ol></div>
        </div>
        <!--/noindex-->

        <div class="site-overview-wrap sidebar-panel">
          <div class="site-author animated" itemprop="author" itemscope itemtype="http://schema.org/Person">
    <img class="site-author-image" itemprop="image" alt="苏木"
      src="/images/avatar.jpg">
  <p class="site-author-name" itemprop="name">苏木</p>
  <div class="site-description" itemprop="description">莫道桑榆晚，为霞尚满天</div>
</div>
<div class="site-state-wrap animated">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
        <a href="/archives/">
          <span class="site-state-item-count">673</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
          <a href="/categories/">
        <span class="site-state-item-count">42</span>
        <span class="site-state-item-name">分类</span></a>
      </div>
      <div class="site-state-item site-state-tags">
        <span class="site-state-item-count">43</span>
        <span class="site-state-item-name">标签</span>
      </div>
  </nav>
</div>
  <div class="links-of-author animated">
      <span class="links-of-author-item">
        <a href="https://github.com/sumumm" title="GitHub → https:&#x2F;&#x2F;github.com&#x2F;sumumm" rel="noopener me" target="_blank"><i class="fab fa-github fa-fw"></i>GitHub</a>
      </span>
  </div>

        </div>
      </div>
    </div>

    
  </aside>


    </div>

    <div class="main-inner post posts-expand">


  


<div class="post-block">
  
  

  <article itemscope itemtype="http://schema.org/Article" class="post-content" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="https://sumumm.github.io/post/6476912c.html">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.jpg">
      <meta itemprop="name" content="苏木">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="苏木">
      <meta itemprop="description" content="莫道桑榆晚，为霞尚满天">
    </span>

    <span hidden itemprop="post" itemscope itemtype="http://schema.org/CreativeWork">
      <meta itemprop="name" content="LV02-GitHubActions-02-工作流程语法 | 苏木">
      <meta itemprop="description" content="">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          LV02-GitHubActions-02-工作流程语法
        </h1>

        <div class="post-meta-container">
          <div class="post-meta">
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-calendar"></i>
      </span>
      <span class="post-meta-item-text">发表于</span>

      <time title="创建时间：2024-12-28 09:54:59" itemprop="dateCreated datePublished" datetime="2024-12-28T09:54:59+08:00">2024-12-28</time>
    </span>
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-folder"></i>
      </span>
      <span class="post-meta-item-text">分类于</span>
        <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
          <a href="/categories/%E5%BC%80%E5%8F%91%E5%B7%A5%E5%85%B7/" itemprop="url" rel="index"><span itemprop="name">开发工具</span></a>
        </span>
          ，
        <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
          <a href="/categories/%E5%BC%80%E5%8F%91%E5%B7%A5%E5%85%B7/05GithubActions/" itemprop="url" rel="index"><span itemprop="name">05GithubActions</span></a>
        </span>
    </span>

  
    <span class="post-meta-break"></span>
    <span class="post-meta-item" title="本文字数">
      <span class="post-meta-item-icon">
        <i class="far fa-file-word"></i>
      </span>
      <span class="post-meta-item-text">本文字数：</span>
      <span>6k</span>
    </span>
    <span class="post-meta-item" title="阅读时长">
      <span class="post-meta-item-icon">
        <i class="far fa-clock"></i>
      </span>
      <span class="post-meta-item-text">阅读时长 &asymp;</span>
      <span>22 分钟</span>
    </span>
</div>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody"><p>GitHub Actions的工作流程怎么写？语法是怎样的？若笔记中有错误或者不合适的地方，欢迎批评指正😃。</p>
<span id="more"></span>

<!-- Photo: https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/02%E5%BC%80%E5%8F%91%E5%B7%A5%E5%85%B7/05GithubActions/LV02-GitHubActions-02-%E5%B7%A5%E4%BD%9C%E6%B5%81%E7%A8%8B%E8%AF%AD%E6%B3%95/img/ -->

<details class="folding-tag" blue><summary> 点击查看使用工具及版本 </summary>
              <div class='content'>
              <table>    <tr>        <td align="center" rowspan="5">PC端开发环境</td>        <td align="center" width=150px>Windows</td>        <td align="left">Windows11</td>    </tr>    <tr>        <td align="center">Ubuntu</td>        <td align="left">Ubuntu20.04.2的64位版本</td>      </tr>    <tr>        <td align="center">VMware® Workstation 17 Pro</td>        <td align="left">17.6.0 build-24238078</td>      </tr>    <tr>        <td align="center">终端软件</td>        <td align="left">MobaXterm(Professional Edition v23.0 Build 5042 (license))</td>    </tr>    <tr>        <td align="center">Win32DiskImager</td>        <td align="left">Win32DiskImager v1.0</td>      </tr>    <tr>        <td align="center" rowspan="3">Linux开发板环境</td>        <td align="center">Linux开发板</td>        <td align="left">正点原子 i.MX6ULL Linux 阿尔法开发板</td>      </tr>    <tr>        <td align="center">uboot</td>        <td align="left">NXP官方提供的uboot，使用的uboot版本为U-Boot 2019.04</td>      </tr>    <tr>        <td align="center">linux内核</td>        <td align="left">linux-4.19.71(NXP官方提供)</td>      </tr></table>
              </div>
            </details>

<details class="folding-tag" blue><summary> 点击查看本文参考资料 </summary>
              <div class='content'>
              <table>    <tr>        <td align="center">分类</td>        <td align="center">网址</td>        <td align="center">说明</td>    </tr>    <tr>        <td align="center" rowspan="2">官方网站</td>        <td align="left"><a href="https://githubdocs.cn/en/actions/writing-workflows/workflow-syntax-for-github-actions" target="_blank">GitHub Actions 工作流程语法</a></td>        <td align="left">GitHub Actions 工作流程语法 - GitHub 文档 - GitHub 文档</td>    </tr>    <tr>        <td align="left"><a href="https://yaml.org/" target="_blank">YAML官网</a></td>        <td align="left">在这里可以找到YAML的基本语法</td>    </tr></table>
              </div>
            </details>

<details class="folding-tag" blue><summary> 点击查看相关文件下载 </summary>
              <div class='content'>
              <table>    <tr>        <td align="center">分类</td>        <td align="center">网址</td>        <td align="center">说明</td>    </tr>    <tr>        <td align="center">---</td>        <td align="left"><a href="" target="_blank">---</a></td>        <td align="left">---</td>    </tr></table>
              </div>
            </details>

<h1 id="一、基本概念"><a href="#一、基本概念" class="headerlink" title="一、基本概念"></a><font size=3>一、基本概念</font></h1><h2 id="1-基本术语"><a href="#1-基本术语" class="headerlink" title="1. 基本术语"></a><font size=3>1. 基本术语</font></h2><p>GitHub Actions 有一些自己的术语。</p>
<p>（1）<strong>workflow</strong> （工作流程）：持续集成一次运行的过程，就是一个 workflow。</p>
<p>（2）<strong>job</strong> （任务）：一个 workflow 由一个或多个 jobs 构成，含义是一次持续集成的运行，可以完成多个任务。</p>
<p>（3）<strong>step</strong>（步骤）：每个 job 由多个 step 构成，一步步完成。</p>
<p>（4）<strong>action</strong> （动作）：每个 step 可以依次执行一个或多个命令（action）。</p>
<p>（5）上下文：上下文是一种访问有关工作流运行、变量、运行器环境、作业和步骤的信息的方法。每个上下文都是一个包含属性的对象，这些属性可以是字符串或其他对象。</p>
<h2 id="2-workflow-文件"><a href="#2-workflow-文件" class="headerlink" title="2. workflow 文件"></a><font size=3>2. workflow 文件</font></h2><p>GitHub Actions 的配置文件叫做 workflow 文件，存放在代码仓库的<code>.github/workflows</code>目录。workflow 文件采用 <a target="_blank" rel="noopener" href="https://yaml.org/spec/1.2.2/">YAML 格式</a>，文件名可以任意取，但是后缀名统一为<code>.yml</code>，比如<code>foo.yml</code>。一个库可以有多个 workflow 文件。GitHub 只要发现<code>.github/workflows</code>目录里面有<code>.yml</code>文件，就会自动运行该文件。</p>
<h2 id="3-上下文"><a href="#3-上下文" class="headerlink" title="3. 上下文"></a><font size=3>3. 上下文</font></h2><p>具体的上下文相关内容可以查看文档：<a target="_blank" rel="noopener" href="https://githubdocs.cn/en/actions/writing-workflows/choosing-what-your-workflow-does/accessing-contextual-information-about-workflow-runs#about-contexts">访问工作流运行的上下文信息 - GitHub Docs - GitHub 文档</a>。里面的<a target="_blank" rel="noopener" href="https://githubdocs.cn/en/actions/writing-workflows/choosing-what-your-workflow-does/accessing-contextual-information-about-workflow-runs#github-context"><code>github</code> 上下文</a>、<a target="_blank" rel="noopener" href="https://githubdocs.cn/en/actions/writing-workflows/choosing-what-your-workflow-does/accessing-contextual-information-about-workflow-runs#secrets-context"><code>secrets</code>上下文 </a>等，后面会经常用到。</p>
<h1 id="二、工作流语法"><a href="#二、工作流语法" class="headerlink" title="二、工作流语法"></a><font size=3>二、工作流语法</font></h1><h2 id="1-name"><a href="#1-name" class="headerlink" title="1. name"></a><font size=3>1. <a target="_blank" rel="noopener" href="https://githubdocs.cn/en/actions/writing-workflows/workflow-syntax-for-github-actions#name"><code>name</code></a></font></h2><p>工作流的名称。GitHub 会在我们的存储库的“Actions”选项卡下显示我们的工作流名称。如果我们省略 <code>name</code>，GitHub 将显示相对于存储库根目录的工作流文件路径。</p>
<h2 id="2-run-name"><a href="#2-run-name" class="headerlink" title="2. run-name"></a><font size=3>2. <a target="_blank" rel="noopener" href="https://githubdocs.cn/en/actions/writing-workflows/workflow-syntax-for-github-actions#run-name"><code>run-name</code></a></font></h2><p>工作流运行的名称，由工作流生成。GitHub 会在我们的仓库“Actions”选项卡的工作流运行列表中显示工作流运行名称。如果省略<code>run-name</code>或仅包含空格，则运行名称将设置为工作流运行的特定于事件的信息。例如，对于由<code>push</code>或<code>pull_request</code>事件触发的 workflow，它将设置为提交消息或拉取请求的标题。</p>
<p>此值可以包含表达式，并可以引用<a target="_blank" rel="noopener" href="https://githubdocs.cn/en/actions/learn-github-actions/contexts#github-context"><code>github</code></a>和<a target="_blank" rel="noopener" href="https://githubdocs.cn/en/actions/learn-github-actions/contexts#inputs-context"><code>inputs</code></a>上下文。</p>
<p><code>run-name</code>示例：</p>
<figure class="highlight yaml"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">run-name:</span> <span class="string">Deploy</span> <span class="string">to</span> <span class="string">$&#123;&#123;</span> <span class="string">inputs.deploy_target</span> <span class="string">&#125;&#125;</span> <span class="string">by</span> <span class="string">@$&#123;&#123;</span> <span class="string">github.actor</span> <span class="string">&#125;&#125;</span></span><br></pre></td></tr></table></figure>

<h2 id="3-on"><a href="#3-on" class="headerlink" title="3. on"></a><font size=3>3. <a target="_blank" rel="noopener" href="https://githubdocs.cn/en/actions/writing-workflows/workflow-syntax-for-github-actions#on"><code>on</code></a></font></h2><p>要自动触发工作流，请使用<code>on</code>定义哪些事件可以导致工作流运行。有关可用事件的列表，请参阅“<a target="_blank" rel="noopener" href="https://githubdocs.cn/en/actions/using-workflows/events-that-trigger-workflows">触发工作流的事件</a>”。</p>
<p>我们可以定义可以触发工作流的单个或多个事件，或设置时间表。还可以将工作流的执行限制为仅针对特定文件、标签或分支更改发生。</p>
<h3 id="3-1-使用单个事件"><a href="#3-1-使用单个事件" class="headerlink" title="3.1 使用单个事件"></a><font size=3>3.1 <a target="_blank" rel="noopener" href="https://githubdocs.cn/en/actions/writing-workflows/workflow-syntax-for-github-actions#using-a-single-event">使用单个事件</a></font></h3><p>可以指定单个事件或多个事件。例如，具有以下<code>on</code>值的工作流将在向存储库中的任何分支推送时运行，或在有人分叉存储库时运行：</p>
<figure class="highlight yaml"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">on:</span> [<span class="string">push</span>, <span class="string">fork</span>]</span><br></pre></td></tr></table></figure>

<p>如果指定多个事件，则只需要发生其中一个事件即可触发工作流。如果工作流的多个触发事件同时发生，则会触发多个工作流运行。</p>
<h3 id="3-2-使用活动类型"><a href="#3-2-使用活动类型" class="headerlink" title="3.2 使用活动类型"></a><font size=3>3.2 <a target="_blank" rel="noopener" href="https://githubdocs.cn/en/actions/writing-workflows/workflow-syntax-for-github-actions#using-activity-types">使用活动类型</a></font></h3><p>某些事件具有活动类型，可以让我们更好地控制工作流何时运行。使用<code>on..types</code>定义将触发工作流运行的事件活动类型。</p>
<p>例如，<code>issue_comment</code>事件具有<code>created</code>、<code>edited</code>和<code>deleted</code>活动类型。如果我们的工作流触发<code>label</code>事件，则只要创建、编辑或删除标签，它就会运行。如果为<code>label</code>事件指定<code>created</code>活动类型，则在创建标签时我们的工作流将运行，但在编辑或删除标签时不会运行。</p>
<figure class="highlight yaml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">on:</span></span><br><span class="line">  <span class="attr">label:</span></span><br><span class="line">    <span class="attr">types:</span></span><br><span class="line">      <span class="bullet">-</span> <span class="string">created</span></span><br></pre></td></tr></table></figure>

<p>如果指定多个活动类型，则只需要发生其中一个事件活动类型即可触发工作流。如果我们的工作流的多个触发事件活动类型同时发生，则会触发多个工作流运行。例如，以下工作流在打开或标记问题时触发。如果打开了一个带有两个标签的问题，则将启动三个工作流运行：一个用于打开的问题事件，两个用于两个标记的问题事件。</p>
<figure class="highlight yaml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">on:</span></span><br><span class="line">  <span class="attr">issues:</span></span><br><span class="line">    <span class="attr">types:</span></span><br><span class="line">      <span class="bullet">-</span> <span class="string">opened</span></span><br><span class="line">      <span class="bullet">-</span> <span class="string">labeled</span></span><br></pre></td></tr></table></figure>

<p>有关每个事件及其活动类型的更多信息，请参阅“<a target="_blank" rel="noopener" href="https://githubdocs.cn/en/actions/using-workflows/events-that-trigger-workflows">触发工作流的事件</a>”。</p>
<h3 id="3-3-使用过滤器"><a href="#3-3-使用过滤器" class="headerlink" title="3.3 使用过滤器"></a><font size=3>3.3 <a target="_blank" rel="noopener" href="https://githubdocs.cn/en/actions/writing-workflows/workflow-syntax-for-github-actions#using-filters">使用过滤器</a></font></h3><p>某些事件具有过滤器，可以让我们更好地控制工作流何时运行。例如，<code>push</code>事件具有<code>branches</code>过滤器，该过滤器会导致我们的工作流仅在向与<code>branches</code>过滤器匹配的分支推送时运行，而不是在任何推送时运行。</p>
<figure class="highlight yaml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">on:</span></span><br><span class="line">  <span class="attr">push:</span></span><br><span class="line">    <span class="attr">branches:</span></span><br><span class="line">      <span class="bullet">-</span> <span class="string">main</span></span><br><span class="line">      <span class="bullet">-</span> <span class="string">&#x27;releases/**&#x27;</span></span><br></pre></td></tr></table></figure>

<h3 id="3-4-结合使用活动类型和过滤器以及多个事件"><a href="#3-4-结合使用活动类型和过滤器以及多个事件" class="headerlink" title="3.4 结合使用活动类型和过滤器以及多个事件"></a><font size=3>3.4 <a target="_blank" rel="noopener" href="https://githubdocs.cn/en/actions/writing-workflows/workflow-syntax-for-github-actions#using-activity-types-and-filters-with-multiple-events">结合使用活动类型和过滤器以及多个事件</a></font></h3><p>如果为事件指定活动类型或过滤器，并且我们的工作流触发多个事件，则必须分别配置每个事件。必须为所有事件附加冒号（<code>:</code>），包括没有配置的事件。例如，具有以下<code>on</code>值的工作流将在以下情况下运行：</p>
<ul>
<li>创建标签</li>
<li>向存储库中的<code>main</code>分支推送</li>
<li>向启用了 GitHub Pages 的分支推送</li>
</ul>
<figure class="highlight yaml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">on:</span></span><br><span class="line">  <span class="attr">label:</span></span><br><span class="line">    <span class="attr">types:</span></span><br><span class="line">      <span class="bullet">-</span> <span class="string">created</span></span><br><span class="line">  <span class="attr">push:</span></span><br><span class="line">    <span class="attr">branches:</span></span><br><span class="line">      <span class="bullet">-</span> <span class="string">main</span></span><br><span class="line">  <span class="attr">page_build:</span></span><br></pre></td></tr></table></figure>

<h3 id="3-5-总结"><a href="#3-5-总结" class="headerlink" title="3.5 总结"></a><font size=3>3.5 总结</font></h3><p><a target="_blank" rel="noopener" href="https://githubdocs.cn/en/actions/writing-workflows/workflow-syntax-for-github-actions#on"><code>on</code></a> 还有很多可用的语法，这里就不再详细写了，都是文档里面的，直接看文档即可。</p>
<h2 id="4-jobs"><a href="#4-jobs" class="headerlink" title="4. jobs"></a><font size=3>4. <a target="_blank" rel="noopener" href="https://githubdocs.cn/en/actions/writing-workflows/workflow-syntax-for-github-actions#jobs"><code>jobs</code></a></font></h2><p>一个工作流运行由一个或多个<code>jobs</code>组成，默认情况下这些<code>jobs</code>并行运行。要顺序运行作业，我们可以使用<code>jobs..needs</code>关键字定义对其他作业的依赖关系。</p>
<p>每个作业都在由<code>runs-on</code>指定的运行器环境中运行。</p>
<p>只要我们在工作流使用限制范围内，就可以运行无限数量的作业。更多信息，请参见关于 GitHub 托管运行器的“<a target="_blank" rel="noopener" href="https://githubdocs.cn/en/actions/learn-github-actions/usage-limits-billing-and-administration">使用限制、计费和管理</a>”以及关于自托管运行器使用限制的“<a target="_blank" rel="noopener" href="https://githubdocs.cn/en/actions/hosting-your-own-runners/managing-self-hosted-runners/about-self-hosted-runners#usage-limits">关于自托管运行器</a>”。</p>
<p>如果我们需要查找工作流运行中运行的作业的唯一标识符，可以使用 GitHub API。更多信息，请参见“<a target="_blank" rel="noopener" href="https://githubdocs.cn/en/rest/actions#workflow-jobs">GitHub Actions 的 REST API 端点</a>”。</p>
<h3 id="4-1-jobs-needs"><a href="#4-1-jobs-needs" class="headerlink" title="4.1 jobs..needs"></a><font size=3>4.1 <a target="_blank" rel="noopener" href="https://githubdocs.cn/en/actions/writing-workflows/workflow-syntax-for-github-actions#jobsjob_idneeds"><code>jobs..needs</code></a></font></h3><h4 id="4-1-1-语法说明"><a href="#4-1-1-语法说明" class="headerlink" title="4.1.1 语法说明"></a><font size=3>4.1.1 语法说明</font></h4><p>使用<code>jobs..needs</code>标识在该作业运行之前必须成功完成的任何作业。它可以是字符串或字符串数组。如果作业失败或被跳过，则所有需要它的作业都将被跳过，除非作业使用导致作业继续的条件表达式。如果运行包含一系列相互依赖的作业，则从失败或跳过点开始，依赖链中的所有作业都将应用失败或跳过。如果我们希望即使依赖的作业没有成功也运行作业，请在<code>jobs..if</code>中使用<code>always()</code>条件表达式。</p>
<h4 id="4-1-2-示例：需要成功的依赖作业"><a href="#4-1-2-示例：需要成功的依赖作业" class="headerlink" title="4.1.2 示例：需要成功的依赖作业"></a><font size=3>4.1.2 <a target="_blank" rel="noopener" href="https://githubdocs.cn/en/actions/writing-workflows/workflow-syntax-for-github-actions#example-requiring-successful-dependent-jobs">示例：需要成功的依赖作业</a></font></h4><figure class="highlight yaml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">jobs:</span></span><br><span class="line">  <span class="attr">job1:</span></span><br><span class="line">  <span class="attr">job2:</span></span><br><span class="line">    <span class="attr">needs:</span> <span class="string">job1</span></span><br><span class="line">  <span class="attr">job3:</span></span><br><span class="line">    <span class="attr">needs:</span> [<span class="string">job1</span>, <span class="string">job2</span>]</span><br></pre></td></tr></table></figure>

<p>在此示例中，<code>job1</code>必须成功完成才能开始<code>job2</code>，而<code>job3</code>等待<code>job1</code>和<code>job2</code>都完成。</p>
<p>此示例中的作业顺序运行</p>
<p>（1）<code>job1</code></p>
<p>（2）<code>job2</code></p>
<p>（3）<code>job3</code></p>
<h4 id="4-1-3-示例：不需要成功的依赖作业"><a href="#4-1-3-示例：不需要成功的依赖作业" class="headerlink" title="4.1.3 示例：不需要成功的依赖作业"></a><font size=3>4.1.3 <a target="_blank" rel="noopener" href="https://githubdocs.cn/en/actions/writing-workflows/workflow-syntax-for-github-actions#example-not-requiring-successful-dependent-jobs">示例：不需要成功的依赖作业</a></font></h4><figure class="highlight yaml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">jobs:</span></span><br><span class="line">  <span class="attr">job1:</span></span><br><span class="line">  <span class="attr">job2:</span></span><br><span class="line">    <span class="attr">needs:</span> <span class="string">job1</span></span><br><span class="line">  <span class="attr">job3:</span></span><br><span class="line">    <span class="attr">if:</span> <span class="string">$&#123;&#123;</span> <span class="string">always()</span> <span class="string">&#125;&#125;</span></span><br><span class="line">    <span class="attr">needs:</span> [<span class="string">job1</span>, <span class="string">job2</span>]</span><br></pre></td></tr></table></figure>

<p>在此示例中，<code>job3</code>使用<code>always()</code>条件表达式，以便在<code>job1</code>和<code>job2</code>完成后始终运行，无论它们是否成功。更多信息，请参见“<a target="_blank" rel="noopener" href="https://githubdocs.cn/en/actions/learn-github-actions/expressions#status-check-functions">在工作流和操作中评估表达式</a>”。</p>
<h3 id="4-2-jobs-runs-on"><a href="#4-2-jobs-runs-on" class="headerlink" title="4.2 jobs..runs-on"></a><font size=3>4.2 <a target="_blank" rel="noopener" href="https://githubdocs.cn/en/actions/writing-workflows/workflow-syntax-for-github-actions#jobsjob_idruns-on"><code>jobs..runs-on</code></a></font></h3><h4 id="4-2-1-语法说明"><a href="#4-2-1-语法说明" class="headerlink" title="4.2.1 语法说明"></a><font size=3>4.2.1 语法说明</font></h4><p>使用<code>jobs..runs-on</code>定义要在其上运行作业的机器类型。</p>
<ul>
<li><p>目标机器可以是<a target="_blank" rel="noopener" href="https://githubdocs.cn/en/actions/writing-workflows/workflow-syntax-for-github-actions#choosing-github-hosted-runners">GitHub 托管运行器</a>、<a target="_blank" rel="noopener" href="https://githubdocs.cn/en/actions/writing-workflows/workflow-syntax-for-github-actions#choosing-runners-in-a-group">更大运行器</a>或<a target="_blank" rel="noopener" href="https://githubdocs.cn/en/actions/writing-workflows/workflow-syntax-for-github-actions#choosing-self-hosted-runners">自托管运行器</a>。</p>
</li>
<li><p>我们可以根据分配给运行器的标签、其组成员身份或两者的组合来定位运行器。</p>
</li>
<li><p>我们可以将<code>runs-on</code>提供为</p>
<ul>
<li>单个字符串</li>
<li>包含字符串的单个变量</li>
<li>字符串数组、包含字符串的变量或两者的组合</li>
<li>使用<code>group</code>或<code>labels</code>键的<code>key: value</code>对</li>
</ul>
</li>
<li><p>如果我们指定字符串或变量数组，我们的工作流将在与所有指定的<code>runs-on</code>值匹配的任何运行器上执行。例如，这里作业将只在具有标签<code>linux</code>、<code>x64</code>和<code>gpu</code>的自托管运行器上运行</p>
<figure class="highlight yaml"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">runs-on:</span> [<span class="string">self-hosted</span>, <span class="string">linux</span>, <span class="string">x64</span>, <span class="string">gpu</span>]</span><br></pre></td></tr></table></figure>

<p>更多信息，请参见“<a target="_blank" rel="noopener" href="https://githubdocs.cn/en/actions/writing-workflows/workflow-syntax-for-github-actions#choosing-self-hosted-runners">选择自托管运行器</a>”。</p>
</li>
<li><p>我们可以在数组中混合字符串和变量。例如</p>
<figure class="highlight yaml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">on:</span></span><br><span class="line">  <span class="attr">workflow_dispatch:</span></span><br><span class="line">    <span class="attr">inputs:</span></span><br><span class="line">      <span class="attr">chosen-os:</span></span><br><span class="line">        <span class="attr">required:</span> <span class="literal">true</span></span><br><span class="line">        <span class="attr">type:</span> <span class="string">choice</span></span><br><span class="line">        <span class="attr">options:</span></span><br><span class="line">        <span class="bullet">-</span> <span class="string">Ubuntu</span></span><br><span class="line">        <span class="bullet">-</span> <span class="string">macOS</span></span><br><span class="line"></span><br><span class="line"><span class="attr">jobs:</span></span><br><span class="line">  <span class="attr">test:</span></span><br><span class="line">    <span class="attr">runs-on:</span> [<span class="string">self-hosted</span>, <span class="string">&quot;$<span class="template-variable">&#123;&#123; inputs.chosen-os &#125;&#125;</span>&quot;</span>]</span><br><span class="line">    <span class="attr">steps:</span></span><br><span class="line">    <span class="bullet">-</span> <span class="attr">run:</span> <span class="string">echo</span> <span class="string">Hello</span> <span class="string">world!</span></span><br></pre></td></tr></table></figure>
</li>
<li><p>如果我们想在多台机器上运行工作流，可以使用<a target="_blank" rel="noopener" href="https://githubdocs.cn/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstrategy"><code>jobs..strategy</code></a>。</p>
</li>
</ul>
<blockquote>
<p>注意：</p>
<p>简单字符串（如<code>self-hosted</code>）不需要引号，但表达式（如<code>&quot;$&#123;&#123; inputs.chosen-os &#125;&#125;&quot;</code>）需要引号。</p>
</blockquote>
<h4 id="4-2-2-选择-GitHub-托管运行器"><a href="#4-2-2-选择-GitHub-托管运行器" class="headerlink" title="4.2.2 选择 GitHub 托管运行器"></a><font size=3>4.2.2 <a target="_blank" rel="noopener" href="https://githubdocs.cn/en/actions/writing-workflows/workflow-syntax-for-github-actions#choosing-github-hosted-runners">选择 GitHub 托管运行器</a></font></h4><p>如果我们使用 GitHub 托管运行器，则每个作业都在<code>runs-on</code>指定的运行器映像的新实例中运行。</p>
<p>当我们使用 GitHub 托管运行器时，<code>runs-on</code>的值是运行器标签或运行器组的名称。标准 GitHub 托管运行器的标签显示在下表中。</p>
<p>更多信息，请参见“<a target="_blank" rel="noopener" href="https://githubdocs.cn/en/actions/using-github-hosted-runners/about-github-hosted-runners/about-github-hosted-runners">关于 GitHub 托管运行器</a>”。GitHub有一些<a target="_blank" rel="noopener" href="https://githubdocs.cn/en/actions/writing-workflows/workflow-syntax-for-github-actions#standard-github-hosted-runners-for-public-repositories">公共存储库的标准 GitHub 托管运行器</a>，对于公共存储库，使用下表中所示工作流标签的作业将在具有关联规格的虚拟机上运行。在公共存储库上使用这些运行器是免费且无限的。</p>
<table>
<thead>
<tr>
<th align="center"><strong>虚拟机</strong></th>
<th align="center"><strong>处理器 (CPU)</strong></th>
<th align="center"><strong>内存 (RAM)</strong></th>
<th align="center"><strong>存储 (SSD)</strong></th>
<th align="left"><strong>工作流标签</strong></th>
</tr>
</thead>
<tbody><tr>
<td align="center">Linux</td>
<td align="center">4</td>
<td align="center">16 GB</td>
<td align="center">14 GB</td>
<td align="left"><code>ubuntu-latest</code>、<code>ubuntu-24.04</code>、<code>ubuntu-22.04</code>、<code>ubuntu-20.04</code></td>
</tr>
<tr>
<td align="center">Windows</td>
<td align="center">4</td>
<td align="center">16 GB</td>
<td align="center">14 GB</td>
<td align="left"><code>windows-latest</code>、<code>windows-2022</code>、<code>windows-2019</code></td>
</tr>
<tr>
<td align="center">macOS</td>
<td align="center">3</td>
<td align="center">14 GB</td>
<td align="center">14 GB</td>
<td align="left"><code>macos-12</code></td>
</tr>
<tr>
<td align="center">macOS</td>
<td align="center">4</td>
<td align="center">14 GB</td>
<td align="center">14 GB</td>
<td align="left"><code>macos-13</code></td>
</tr>
<tr>
<td align="center">macOS</td>
<td align="center">3 (M1)</td>
<td align="center">7 GB</td>
<td align="center">14 GB</td>
<td align="left"><code>macos-latest</code>、<code>macos-14</code>、<code>macos-15</code> [公开预览]</td>
</tr>
</tbody></table>
<p>GitHub还有一些<a target="_blank" rel="noopener" href="https://githubdocs.cn/en/actions/writing-workflows/workflow-syntax-for-github-actions#standard-github-hosted-runners-for--private-repositories">私有存储库的标准 GitHub 托管运行器</a>。对于私有存储库，使用下表中所示工作流标签的作业将在具有关联规格的虚拟机上运行。这些运行器使用我们的 GitHub 帐户分配的免费分钟数，然后按分钟费率收费。更多信息，请参见“<a target="_blank" rel="noopener" href="https://githubdocs.cn/en/billing/managing-billing-for-github-actions/about-billing-for-github-actions#per-minute-rates">关于 GitHub Actions 的计费</a>”。</p>
<table>
<thead>
<tr>
<th align="center"><strong>虚拟机</strong></th>
<th align="center"><strong>处理器 (CPU)</strong></th>
<th align="center"><strong>内存 (RAM)</strong></th>
<th align="center"><strong>存储 (SSD)</strong></th>
<th><strong>工作流标签</strong></th>
</tr>
</thead>
<tbody><tr>
<td align="center">Linux</td>
<td align="center">2</td>
<td align="center">7 GB</td>
<td align="center">14 GB</td>
<td><code>ubuntu-latest</code>、<code>ubuntu-24.04</code>、<code>ubuntu-22.04</code>、<code>ubuntu-20.04</code></td>
</tr>
<tr>
<td align="center">Windows</td>
<td align="center">2</td>
<td align="center">7 GB</td>
<td align="center">14 GB</td>
<td><code>windows-latest</code>、<code>windows-2022</code>、<code>windows-2019</code></td>
</tr>
<tr>
<td align="center">macOS</td>
<td align="center">3</td>
<td align="center">14 GB</td>
<td align="center">14 GB</td>
<td><code>macos-12</code></td>
</tr>
<tr>
<td align="center">macOS</td>
<td align="center">4</td>
<td align="center">14 GB</td>
<td align="center">14 GB</td>
<td><code>macos-13</code></td>
</tr>
<tr>
<td align="center">macOS</td>
<td align="center">3 (M1)</td>
<td align="center">7 GB</td>
<td align="center">14 GB</td>
<td><code>macos-latest</code>、<code>macos-14</code>、<code>macos-15</code> [公开预览]</td>
</tr>
</tbody></table>
<p>除了标准的 GitHub 托管运行器外，GitHub 还为使用 GitHub Team 和 GitHub Enterprise Cloud 计划的客户提供一系列具有高级功能的托管虚拟机——例如，更多核心和磁盘空间、GPU 加速的机器和 ARM 架构的机器。更多信息，请参阅“<a target="_blank" rel="noopener" href="https://githubdocs.cn/en/actions/using-github-hosted-runners/about-larger-runners/about-larger-runners">关于大型运行器</a>”。</p>
<blockquote>
<p>注意</p>
<p><code>-latest</code> 运行器镜像是 GitHub 提供的最新稳定镜像，可能不是操作系统供应商提供的最新操作系统版本。</p>
</blockquote>
<blockquote>
<p>警告</p>
<p>Beta 版和已弃用的镜像按“现状”、“包含所有缺陷”和“按可用性”提供，不包含在服务等级协议和保修范围内。Beta 版镜像可能不包含在客户支持范围内。</p>
</blockquote>
<p>下面代码指定虚拟机环境为<code>ubuntu-20.04</code>：</p>
<figure class="highlight yaml"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">runs-on:</span> <span class="string">ubuntu-20.04</span></span><br></pre></td></tr></table></figure>

<h4 id="4-2-3-选择自托管运行器"><a href="#4-2-3-选择自托管运行器" class="headerlink" title="4.2.3 选择自托管运行器"></a><font size=3>4.2.3 <a target="_blank" rel="noopener" href="https://githubdocs.cn/en/actions/writing-workflows/workflow-syntax-for-github-actions#choosing-self-hosted-runners">选择自托管运行器</a></font></h4><p>要为我们的作业指定自托管运行器，可以在我们的工作流文件中使用自托管运行器标签配置<code>runs-on</code>。</p>
<p>自托管运行器可能具有<code>self-hosted</code>标签。设置自托管运行器时，默认情况下GitHub Actions将包含标签<code>self-hosted</code>。我们可以传入<code>--no-default-labels</code>标志以防止应用自托管标签。标签可用于为运行器创建目标选项，例如操作系统或架构，GitHub Actions建议提供一个以<code>self-hosted</code>开头的标签数组（此标签必须列在首位），然后根据需要包含其他标签。当我们指定一个标签数组时，作业将排队到具有我们指定的所有标签的运行器上。</p>
<p>请注意，Actions 运行器控制器不支持多个标签，也不支持<code>self-hosted</code>标签。</p>
<p><a target="_blank" rel="noopener" href="https://githubdocs.cn/en/actions/writing-workflows/workflow-syntax-for-github-actions#example-using-labels-for-runner-selection">示例：使用标签进行运行器选择</a></p>
<figure class="highlight yaml"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">runs-on:</span> [<span class="string">self-hosted</span>, <span class="string">linux</span>]</span><br></pre></td></tr></table></figure>

<p>更多信息，请参阅“<a target="_blank" rel="noopener" href="https://githubdocs.cn/en/actions/hosting-your-own-runners/managing-self-hosted-runners/about-self-hosted-runners">关于自托管运行器</a>”和“<a target="_blank" rel="noopener" href="https://githubdocs.cn/en/actions/hosting-your-own-runners/managing-self-hosted-runners/using-self-hosted-runners-in-a-workflow">在工作流中使用自托管运行器</a>”。</p>
<h3 id="4-3-jobs-if"><a href="#4-3-jobs-if" class="headerlink" title="4.3 jobs..if"></a><font size=3>4.3 <a target="_blank" rel="noopener" href="https://githubdocs.cn/en/actions/writing-workflows/workflow-syntax-for-github-actions#jobsjob_idif"><code>jobs..if</code></a></font></h3><h4 id="4-3-1-语法说明"><a href="#4-3-1-语法说明" class="headerlink" title="4.3.1 语法说明"></a><font size=3>4.3.1 语法说明</font></h4><p>我们可以使用<code>jobs..if</code>条件来阻止作业运行，除非满足某个条件。我们可以使用任何受支持的上下文和表达式来创建条件。有关此键中支持哪些上下文的更多信息，请参见“<a target="_blank" rel="noopener" href="https://githubdocs.cn/en/actions/learn-github-actions/contexts#context-availability">访问有关工作流运行的上下文信息</a>”。</p>
<blockquote>
<p>注意</p>
<p><code>jobs..if</code>条件在应用<a target="_blank" rel="noopener" href="https://githubdocs.cn/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstrategymatrix"><code>jobs..strategy.matrix</code></a>之前进行评估。</p>
</blockquote>
<p>当我们在<code>if</code>条件中使用表达式时，可以选择省略<code>$&#123;&#123; &#125;&#125;</code>表达式语法，因为 GitHub Actions 会自动将<code>if</code>条件评估为表达式。但是，此例外并非在所有地方都适用。</p>
<p>当表达式以<code>!</code>开头时，我们必须始终使用<code>$&#123;&#123; &#125;&#125;</code>表达式语法或使用<code>&#39;&#39;</code>、<code>&quot;&quot;</code>或<code>()</code>进行转义，因为<code>!</code>是 YAML 格式中的保留符号。例如</p>
<figure class="highlight yaml"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">if:</span> <span class="string">$&#123;&#123;</span> <span class="string">!</span> <span class="string">startsWith(github.ref,</span> <span class="string">&#x27;refs/tags/&#x27;</span><span class="string">)</span> <span class="string">&#125;&#125;</span></span><br></pre></td></tr></table></figure>

<p>更多信息，请参见“<a target="_blank" rel="noopener" href="https://githubdocs.cn/en/actions/learn-github-actions/expressions">在工作流和操作中评估表达式</a>”。</p>
<h4 id="4-3-2-示例：仅为特定存储库运行作业"><a href="#4-3-2-示例：仅为特定存储库运行作业" class="headerlink" title="4.3.2 示例：仅为特定存储库运行作业"></a><font size=3>4.3.2 <a target="_blank" rel="noopener" href="https://githubdocs.cn/en/actions/writing-workflows/workflow-syntax-for-github-actions#example-only-run-job-for-specific-repository">示例：仅为特定存储库运行作业</a></font></h4><p>此示例使用<code>if</code>来控制<code>production-deploy</code>作业何时运行。它仅在存储库名为<code>octo-repo-prod</code>且位于<code>octo-org</code>组织内时运行。否则，该作业将标记为已跳过。</p>
<figure class="highlight yaml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">name:</span> <span class="string">example-workflow</span></span><br><span class="line"><span class="attr">on:</span> [<span class="string">push</span>]</span><br><span class="line"><span class="attr">jobs:</span></span><br><span class="line">  <span class="attr">production-deploy:</span></span><br><span class="line">    <span class="attr">if:</span> <span class="string">github.repository</span> <span class="string">==</span> <span class="string">&#x27;octo-org/octo-repo-prod&#x27;</span></span><br><span class="line">    <span class="attr">runs-on:</span> <span class="string">ubuntu-latest</span></span><br><span class="line">    <span class="attr">steps:</span></span><br><span class="line">      <span class="bullet">-</span> <span class="attr">uses:</span> <span class="string">actions/checkout@v4</span></span><br><span class="line">      <span class="bullet">-</span> <span class="attr">uses:</span> <span class="string">actions/setup-node@v4</span></span><br><span class="line">        <span class="attr">with:</span></span><br><span class="line">          <span class="attr">node-version:</span> <span class="string">&#x27;14&#x27;</span></span><br><span class="line">      <span class="bullet">-</span> <span class="attr">run:</span> <span class="string">npm</span> <span class="string">install</span> <span class="string">-g</span> <span class="string">bats</span></span><br></pre></td></tr></table></figure>

<h4 id="4-3-3-示例：仅为特定tag创建时运行作业"><a href="#4-3-3-示例：仅为特定tag创建时运行作业" class="headerlink" title="4.3.3 示例：仅为特定tag创建时运行作业"></a><font size=3>4.3.3 示例：仅为特定tag创建时运行作业</font></h4><figure class="highlight yaml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">name:</span> <span class="string">example-workflow</span></span><br><span class="line"><span class="attr">on:</span> [<span class="string">push</span>]</span><br><span class="line"><span class="attr">jobs:</span></span><br><span class="line">  <span class="attr">production-deploy:</span></span><br><span class="line">    <span class="attr">if:</span> <span class="string">github.event_name</span> <span class="string">==</span> <span class="string">&#x27;push&#x27;</span> <span class="string">&amp;&amp;</span> <span class="string">startsWith(github.ref,</span> <span class="string">&#x27;refs/tags&#x27;</span><span class="string">)</span> </span><br><span class="line">    <span class="attr">runs-on:</span> <span class="string">ubuntu-latest</span></span><br><span class="line">    <span class="attr">steps:</span></span><br><span class="line">      <span class="bullet">-</span> <span class="attr">uses:</span> <span class="string">actions/checkout@v4</span></span><br><span class="line">      <span class="bullet">-</span> <span class="attr">uses:</span> <span class="string">actions/setup-node@v4</span></span><br><span class="line">        <span class="attr">with:</span></span><br><span class="line">          <span class="attr">node-version:</span> <span class="string">&#x27;14&#x27;</span></span><br><span class="line">      <span class="bullet">-</span> <span class="attr">run:</span> <span class="string">npm</span> <span class="string">install</span> <span class="string">-g</span> <span class="string">bats</span></span><br></pre></td></tr></table></figure>

<p>这个作业将会在本地执行<code>git push origin tag_name</code>的时候执行，<code>git push</code>的时候不会执行。</p>
<h3 id="4-4-jobs-steps"><a href="#4-4-jobs-steps" class="headerlink" title="4.4 jobs..steps"></a><font size=3>4.4 <a target="_blank" rel="noopener" href="https://githubdocs.cn/en/actions/writing-workflows/workflow-syntax-for-github-actions#jobsjob_idsteps"><code>jobs..steps</code></a></font></h3><h4 id="4-4-1-语法说明"><a href="#4-4-1-语法说明" class="headerlink" title="4.4.1 语法说明"></a><font size=3>4.4.1 语法说明</font></h4><p>一个作业包含一系列称为<code>steps</code>的任务。步骤可以运行命令、运行设置任务或在我们的仓库、公共仓库或在 Docker 注册表中发布的动作中运行操作。并非所有步骤都运行操作，但所有操作都作为步骤运行。每个步骤在运行器环境中的自己的进程中运行，并可以访问工作区和文件系统。由于步骤在其自己的进程中运行，因此环境变量的更改不会在步骤之间保留。GitHub 提供内置步骤来设置和完成作业。</p>
<p>GitHub 仅显示前 1,000 个检查，但是，只要我们在工作流使用限制内，我们可以运行无限数量的步骤。有关更多信息，请参阅针对 GitHub 托管运行器的“<a target="_blank" rel="noopener" href="https://githubdocs.cn/en/actions/learn-github-actions/usage-limits-billing-and-administration">使用限制、计费和管理</a>”以及针对自托管运行器的“<a target="_blank" rel="noopener" href="https://githubdocs.cn/en/actions/hosting-your-own-runners/managing-self-hosted-runners/about-self-hosted-runners#usage-limits">关于自托管运行器</a>”以了解自托管运行器的使用限制。</p>
<h4 id="4-4-2-jobs-steps示例"><a href="#4-4-2-jobs-steps示例" class="headerlink" title="4.4.2 jobs..steps示例"></a><font size=3>4.4.2 <a target="_blank" rel="noopener" href="https://githubdocs.cn/en/actions/writing-workflows/workflow-syntax-for-github-actions#example-of-jobsjob_idsteps"><code>jobs..steps</code>示例</a></font></h4><figure class="highlight yaml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">name:</span> <span class="string">Greeting</span> <span class="string">from</span> <span class="string">Mona</span></span><br><span class="line"></span><br><span class="line"><span class="attr">on:</span> <span class="string">push</span></span><br><span class="line"></span><br><span class="line"><span class="attr">jobs:</span></span><br><span class="line">  <span class="attr">my-job:</span></span><br><span class="line">    <span class="attr">name:</span> <span class="string">My</span> <span class="string">Job</span></span><br><span class="line">    <span class="attr">runs-on:</span> <span class="string">ubuntu-latest</span></span><br><span class="line">    <span class="attr">steps:</span></span><br><span class="line">      <span class="bullet">-</span> <span class="attr">name:</span> <span class="string">Print</span> <span class="string">a</span> <span class="string">greeting</span></span><br><span class="line">        <span class="attr">env:</span></span><br><span class="line">          <span class="attr">MY_VAR:</span> <span class="string">Hi</span> <span class="string">there!</span> <span class="string">My</span> <span class="string">name</span> <span class="string">is</span></span><br><span class="line">          <span class="attr">FIRST_NAME:</span> <span class="string">Mona</span></span><br><span class="line">          <span class="attr">MIDDLE_NAME:</span> <span class="string">The</span></span><br><span class="line">          <span class="attr">LAST_NAME:</span> <span class="string">Octocat</span></span><br><span class="line">        <span class="attr">run:</span> <span class="string">|</span></span><br><span class="line">          <span class="string">echo</span> <span class="string">$MY_VAR</span> <span class="string">$FIRST_NAME</span> <span class="string">$MIDDLE_NAME</span> <span class="string">$LAST_NAME.</span></span><br></pre></td></tr></table></figure>

<h3 id="4-5-jobs-steps-uses"><a href="#4-5-jobs-steps-uses" class="headerlink" title="4.5 jobs..steps..uses"></a><font size=3>4.5 <a target="_blank" rel="noopener" href="https://githubdocs.cn/en/actions/writing-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsuses"><code>jobs..steps..uses</code></a></font></h3><h4 id="4-5-1-语法说明"><a href="#4-5-1-语法说明" class="headerlink" title="4.5.1 语法说明"></a><font size=3>4.5.1 语法说明</font></h4><p>选择要作为作业中步骤的一部分运行的操作。操作是可重用的代码单元。我们可以使用与工作流相同的仓库中定义的操作、公共仓库中的操作或<a target="_blank" rel="noopener" href="https://hub.docker.com/">已发布的 Docker 容器映像</a>中的操作。</p>
<p>Github Actions强烈建议我们通过指定 Git ref、SHA 或 Docker 标记来包含我们正在使用的操作的版本。如果我们没有指定版本，它可能会破坏我们的工作流，或者在操作所有者发布更新时导致意外行为。</p>
<ul>
<li>使用已发布操作版本的提交 SHA 对稳定性和安全性最安全。</li>
<li>如果操作发布主要版本标记，则我们应该期望收到关键修复和安全补丁，同时仍保留兼容性。请注意，此行为取决于操作作者的决定。</li>
<li>使用操作的默认分支可能很方便，但是，如果有人发布具有重大更改的新主要版本，我们的工作流可能会中断。</li>
</ul>
<p>某些操作需要我们必须使用<a target="_blank" rel="noopener" href="https://githubdocs.cn/en/actions/writing-workflows/workflow-syntax-for-github-actions#jobsjob_idstepswith"><code>with</code></a>关键字设置的输入。查看操作的自述文件以确定所需的输入。</p>
<p>操作是 JavaScript 文件或 Docker 容器。如果我们正在使用的操作是 Docker 容器，则必须在 Linux 环境中运行作业。有关更多详细信息，请参阅<a target="_blank" rel="noopener" href="https://githubdocs.cn/en/actions/writing-workflows/workflow-syntax-for-github-actions#jobsjob_idruns-on"><code>runs-on</code></a>。</p>
<h4 id="4-5-2-示例：使用版本化的操作"><a href="#4-5-2-示例：使用版本化的操作" class="headerlink" title="4.5.2 示例：使用版本化的操作"></a><font size=3>4.5.2 <a target="_blank" rel="noopener" href="https://githubdocs.cn/en/actions/writing-workflows/workflow-syntax-for-github-actions#example-using-versioned-actions">示例：使用版本化的操作</a></font></h4><figure class="highlight yaml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">steps:</span></span><br><span class="line">  <span class="comment"># Reference a specific commit</span></span><br><span class="line">  <span class="bullet">-</span> <span class="attr">uses:</span> <span class="string">actions/checkout@8f4b7f84864484a7bf31766abe9204da3cbe65b3</span></span><br><span class="line">  <span class="comment"># Reference the major version of a release</span></span><br><span class="line">  <span class="bullet">-</span> <span class="attr">uses:</span> <span class="string">actions/checkout@v4</span></span><br><span class="line">  <span class="comment"># Reference a specific version</span></span><br><span class="line">  <span class="bullet">-</span> <span class="attr">uses:</span> <span class="string">actions/checkout@v4.2.0</span></span><br><span class="line">  <span class="comment"># Reference a branch</span></span><br><span class="line">  <span class="bullet">-</span> <span class="attr">uses:</span> <span class="string">actions/checkout@main</span></span><br></pre></td></tr></table></figure>

<h4 id="4-5-3-示例：使用公共操作"><a href="#4-5-3-示例：使用公共操作" class="headerlink" title="4.5.3 示例：使用公共操作"></a><font size=3>4.5.3 <a target="_blank" rel="noopener" href="https://githubdocs.cn/en/actions/writing-workflows/workflow-syntax-for-github-actions#example-using-a-public-action">示例：使用公共操作</a></font></h4><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">&#123;owner&#125;/&#123;repo&#125;@&#123;ref&#125;</span><br></pre></td></tr></table></figure>

<p>您可以在公共 GitHub 仓库中指定分支、ref 或 SHA。</p>
<figure class="highlight yaml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">jobs:</span></span><br><span class="line">  <span class="attr">my_first_job:</span></span><br><span class="line">    <span class="attr">steps:</span></span><br><span class="line">      <span class="bullet">-</span> <span class="attr">name:</span> <span class="string">My</span> <span class="string">first</span> <span class="string">step</span></span><br><span class="line">        <span class="comment"># Uses the default branch of a public repository</span></span><br><span class="line">        <span class="attr">uses:</span> <span class="string">actions/heroku@main</span></span><br><span class="line">      <span class="bullet">-</span> <span class="attr">name:</span> <span class="string">My</span> <span class="string">second</span> <span class="string">step</span></span><br><span class="line">        <span class="comment"># Uses a specific version tag of a public repository</span></span><br><span class="line">        <span class="attr">uses:</span> <span class="string">actions/aws@v2.0.1</span></span><br></pre></td></tr></table></figure>

<h4 id="4-5-4-示例：在子目录中使用公共操作"><a href="#4-5-4-示例：在子目录中使用公共操作" class="headerlink" title="4.5.4 示例：在子目录中使用公共操作"></a><font size=3>4.5.4 <a target="_blank" rel="noopener" href="https://githubdocs.cn/en/actions/writing-workflows/workflow-syntax-for-github-actions#example-using-a-public-action-in-a-subdirectory">示例：在子目录中使用公共操作</a></font></h4><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">&#123;owner&#125;/&#123;repo&#125;/&#123;path&#125;@&#123;ref&#125;</span><br></pre></td></tr></table></figure>

<p>公共 GitHub 仓库中特定分支、ref 或 SHA 的子目录。</p>
<figure class="highlight yaml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">jobs:</span></span><br><span class="line">  <span class="attr">my_first_job:</span></span><br><span class="line">    <span class="attr">steps:</span></span><br><span class="line">      <span class="bullet">-</span> <span class="attr">name:</span> <span class="string">My</span> <span class="string">first</span> <span class="string">step</span></span><br><span class="line">        <span class="attr">uses:</span> <span class="string">actions/aws/ec2@main</span></span><br></pre></td></tr></table></figure>

<h4 id="4-5-5-示例：在与工作流相同的仓库中使用操作"><a href="#4-5-5-示例：在与工作流相同的仓库中使用操作" class="headerlink" title="4.5.5 示例：在与工作流相同的仓库中使用操作"></a><font size=3>4.5.5 <a target="_blank" rel="noopener" href="https://githubdocs.cn/en/actions/writing-workflows/workflow-syntax-for-github-actions#example-using-an-action-in-the-same-repository-as-the-workflow">示例：在与工作流相同的仓库中使用操作</a></font></h4><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">./path/to/dir</span><br></pre></td></tr></table></figure>

<p>包含工作流仓库中操作的目录的路径。您必须在使用操作之前检出您的仓库。</p>
<p>示例仓库文件结构</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">|-- hello-world (repository)</span><br><span class="line">|   |__ .github</span><br><span class="line">|       └── workflows</span><br><span class="line">|           └── my-first-workflow.yml</span><br><span class="line">|       └── actions</span><br><span class="line">|           |__ hello-world-action</span><br><span class="line">|               └── action.yml</span><br></pre></td></tr></table></figure>

<p>该路径相对于默认工作目录（<code>github.workspace</code>、<code>$GITHUB_WORKSPACE</code>）。如果操作将仓库检出到与工作流不同的位置，则必须更新用于本地操作的相对路径。</p>
<p>示例工作流文件</p>
<figure class="highlight yaml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">jobs:</span></span><br><span class="line">  <span class="attr">my_first_job:</span></span><br><span class="line">    <span class="attr">runs-on:</span> <span class="string">ubuntu-latest</span></span><br><span class="line">    <span class="attr">steps:</span></span><br><span class="line">      <span class="comment"># This step checks out a copy of your repository.</span></span><br><span class="line">      <span class="bullet">-</span> <span class="attr">name:</span> <span class="string">My</span> <span class="string">first</span> <span class="string">step</span> <span class="bullet">-</span> <span class="string">check</span> <span class="string">out</span> <span class="string">repository</span></span><br><span class="line">        <span class="attr">uses:</span> <span class="string">actions/checkout@v4</span></span><br><span class="line">      <span class="comment"># This step references the directory that contains the action.</span></span><br><span class="line">      <span class="bullet">-</span> <span class="attr">name:</span> <span class="string">Use</span> <span class="string">local</span> <span class="string">hello-world-action</span></span><br><span class="line">        <span class="attr">uses:</span> <span class="string">./.github/actions/hello-world-action</span></span><br></pre></td></tr></table></figure>

<h4 id="4-5-6-示例：使用-Docker-Hub-操作"><a href="#4-5-6-示例：使用-Docker-Hub-操作" class="headerlink" title="4.5.6 示例：使用 Docker Hub 操作"></a><font size=3>4.5.6 <a target="_blank" rel="noopener" href="https://githubdocs.cn/en/actions/writing-workflows/workflow-syntax-for-github-actions#example-using-a-docker-hub-action">示例：使用 Docker Hub 操作</a></font></h4><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">docker://&#123;image&#125;:&#123;tag&#125;</span><br></pre></td></tr></table></figure>

<p>在<a target="_blank" rel="noopener" href="https://hub.docker.com/">Docker Hub</a>上发布的 Docker 映像。</p>
<figure class="highlight yaml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">jobs:</span></span><br><span class="line">  <span class="attr">my_first_job:</span></span><br><span class="line">    <span class="attr">steps:</span></span><br><span class="line">      <span class="bullet">-</span> <span class="attr">name:</span> <span class="string">My</span> <span class="string">first</span> <span class="string">step</span></span><br><span class="line">        <span class="attr">uses:</span> <span class="string">docker://alpine:3.8</span></span><br></pre></td></tr></table></figure>

<h4 id="4-5-7-示例：使用-GitHub-Packages-容器注册表"><a href="#4-5-7-示例：使用-GitHub-Packages-容器注册表" class="headerlink" title="4.5.7 示例：使用 GitHub Packages 容器注册表"></a><font size=3>4.5.7 <a target="_blank" rel="noopener" href="https://githubdocs.cn/en/actions/writing-workflows/workflow-syntax-for-github-actions#example-using-the-github-packages-container-registry">示例：使用 GitHub Packages 容器注册表</a></font></h4><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">docker://&#123;host&#125;/&#123;image&#125;:&#123;tag&#125;</span><br></pre></td></tr></table></figure>

<p>GitHub Packages 容器注册表中的公共 Docker 映像。</p>
<figure class="highlight yaml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">jobs:</span></span><br><span class="line">  <span class="attr">my_first_job:</span></span><br><span class="line">    <span class="attr">steps:</span></span><br><span class="line">      <span class="bullet">-</span> <span class="attr">name:</span> <span class="string">My</span> <span class="string">first</span> <span class="string">step</span></span><br><span class="line">        <span class="attr">uses:</span> <span class="string">docker://ghcr.io/OWNER/IMAGE_NAME</span></span><br></pre></td></tr></table></figure>

<h4 id="4-5-8-示例：使用-Docker-公共注册表操作"><a href="#4-5-8-示例：使用-Docker-公共注册表操作" class="headerlink" title="4.5.8 示例：使用 Docker 公共注册表操作"></a><font size=3>4.5.8 <a target="_blank" rel="noopener" href="https://githubdocs.cn/en/actions/writing-workflows/workflow-syntax-for-github-actions#example-using-a-docker-public-registry-action">示例：使用 Docker 公共注册表操作</a></font></h4><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">docker://&#123;host&#125;/&#123;image&#125;:&#123;tag&#125;</span><br></pre></td></tr></table></figure>

<p>公共注册表中的 Docker 映像。此示例使用 <code>gcr.io</code> 中的 Google Container Registry。</p>
<figure class="highlight yaml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">jobs:</span></span><br><span class="line">  <span class="attr">my_first_job:</span></span><br><span class="line">    <span class="attr">steps:</span></span><br><span class="line">      <span class="bullet">-</span> <span class="attr">name:</span> <span class="string">My</span> <span class="string">first</span> <span class="string">step</span></span><br><span class="line">        <span class="attr">uses:</span> <span class="string">docker://gcr.io/cloud-builders/gradle</span></span><br></pre></td></tr></table></figure>

<h4 id="4-5-9-示例：在与工作流不同的私有仓库中使用操作"><a href="#4-5-9-示例：在与工作流不同的私有仓库中使用操作" class="headerlink" title="4.5.9 示例：在与工作流不同的私有仓库中使用操作"></a><font size=3>4.5.9 <a target="_blank" rel="noopener" href="https://githubdocs.cn/en/actions/writing-workflows/workflow-syntax-for-github-actions#example-using-an-action-inside-a-different-private-repository-than-the-workflow">示例：在与工作流不同的私有仓库中使用操作</a></font></h4><p>您的工作流必须检出私有仓库并本地引用操作。生成个人访问令牌并将令牌添加为密钥。有关更多信息，请参阅“<a target="_blank" rel="noopener" href="https://githubdocs.cn/en/authentication/keeping-your-account-and-data-secure/creating-a-personal-access-token">管理您的个人访问令牌</a>”和“<a target="_blank" rel="noopener" href="https://githubdocs.cn/en/actions/security-guides/using-secrets-in-github-actions">在 GitHub Actions 中使用密钥</a>”。</p>
<p>将示例中的<code>PERSONAL_ACCESS_TOKEN</code>替换为您密钥的名称。</p>
<figure class="highlight yaml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">jobs:</span></span><br><span class="line">  <span class="attr">my_first_job:</span></span><br><span class="line">    <span class="attr">steps:</span></span><br><span class="line">      <span class="bullet">-</span> <span class="attr">name:</span> <span class="string">Check</span> <span class="string">out</span> <span class="string">repository</span></span><br><span class="line">        <span class="attr">uses:</span> <span class="string">actions/checkout@v4</span></span><br><span class="line">        <span class="attr">with:</span></span><br><span class="line">          <span class="attr">repository:</span> <span class="string">octocat/my-private-repo</span></span><br><span class="line">          <span class="attr">ref:</span> <span class="string">v1.0</span></span><br><span class="line">          <span class="attr">token:</span> <span class="string">$&#123;&#123;</span> <span class="string">secrets.PERSONAL_ACCESS_TOKEN</span> <span class="string">&#125;&#125;</span></span><br><span class="line">          <span class="attr">path:</span> <span class="string">./.github/actions/my-private-repo</span></span><br><span class="line">      <span class="bullet">-</span> <span class="attr">name:</span> <span class="string">Run</span> <span class="string">my</span> <span class="string">action</span></span><br><span class="line">        <span class="attr">uses:</span> <span class="string">./.github/actions/my-private-repo/my-action</span></span><br></pre></td></tr></table></figure>

<p>或者，使用 GitHub App 代替个人访问令牌，以确保即使个人访问令牌所有者离开，您的工作流也能继续运行。有关更多信息，请参阅“<a target="_blank" rel="noopener" href="https://githubdocs.cn/en/apps/creating-github-apps/guides/making-authenticated-api-requests-with-a-github-app-in-a-github-actions-workflow">在 GitHub Actions 工作流中使用 GitHub App 进行身份验证的 API 请求</a>”。</p>
<h1 id="三、常用公共actions"><a href="#三、常用公共actions" class="headerlink" title="三、常用公共actions"></a><font size=3>三、常用公共actions</font></h1><h2 id="1-actions-checkout"><a href="#1-actions-checkout" class="headerlink" title="1. actions&#x2F;checkout"></a><font size=3>1. <a target="_blank" rel="noopener" href="https://github.com/actions/checkout">actions&#x2F;checkout</a></font></h2><figure class="highlight yaml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">jobs:</span></span><br><span class="line">    <span class="attr">steps:</span></span><br><span class="line">      <span class="bullet">-</span> <span class="attr">uses:</span> <span class="string">actions/checkout@v4</span></span><br></pre></td></tr></table></figure>

<p>checkout仓库地址在这里：<a target="_blank" rel="noopener" href="https://github.com/actions/checkout">GitHub - actions&#x2F;checkout: Action for checking out a repo</a>。Checkout V4 是 GitHub Actions 中的一个核心动作，旨在简化工作流程中对仓库的检出操作。通过 Checkout V4，用户可以轻松地将仓库检出到 $GITHUB_WORKSPACE 中，从而使工作流程能够访问仓库内容。该动作支持多种配置选项，包括检出特定分支、标签或 SHA，以及配置 SSH 密钥和令牌等，极大地增强了工作流程的灵活性和安全性。</p>
<p>说简单点，就是，现在我们在<a target="_blank" rel="noopener" href="https://github.com/sumumm/linux-release">sumumm&#x2F;linux-release</a>这个仓库中启动了<a target="_blank" rel="noopener" href="https://github.com/sumumm/linux-release/blob/master/.github/workflows/release.yml">.github&#x2F;workflows&#x2F;release.yml</a>中的工作流，这个时候，通过<code>jobs..steps..uses</code>就可以将<a target="_blank" rel="noopener" href="https://github.com/sumumm/linux-release">sumumm&#x2F;linux-release</a>这个仓库检出到现在正在运行的ubuntu系统中，检出之后，我们就可以使用  github.workspace 来表示当前仓库<a target="_blank" rel="noopener" href="https://github.com/sumumm/linux-release">sumumm&#x2F;linux-release</a>的路径，然后通过以下方式访问其中的文件：</p>
<figure class="highlight yaml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">jobs:</span></span><br><span class="line">  <span class="attr">build:</span></span><br><span class="line">    <span class="attr">runs-on:</span> <span class="string">ubuntu-20.04</span> <span class="comment"># ubuntu-latest ubuntu的最新版本</span></span><br><span class="line">    <span class="attr">steps:</span></span><br><span class="line">      <span class="bullet">-</span> <span class="attr">uses:</span> <span class="string">actions/checkout@v4</span></span><br><span class="line">      <span class="bullet">-</span> <span class="attr">name:</span> <span class="string">拷贝存储库中的文件</span></span><br><span class="line">        <span class="attr">run:</span> <span class="string">|</span></span><br><span class="line">          <span class="string">cp</span> <span class="string">-pvf</span> <span class="string">$&#123;&#123;</span> <span class="string">github.workspace</span> <span class="string">&#125;&#125;/linux_app_demo/helloworld_demo.c</span> <span class="string">./</span></span><br></pre></td></tr></table></figure>

<h2 id="2-softprops-action-gh-release"><a href="#2-softprops-action-gh-release" class="headerlink" title="2.  softprops&#x2F;action-gh-release"></a><font size=3>2. <a target="_blank" rel="noopener" href="https://github.com/softprops/action-gh-release"> softprops&#x2F;action-gh-release</a></font></h2><figure class="highlight yaml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">jobs:</span></span><br><span class="line">  <span class="attr">build:</span></span><br><span class="line">    <span class="attr">runs-on:</span> <span class="string">ubuntu-20.04</span> <span class="comment"># ubuntu-latest ubuntu的最新版本</span></span><br><span class="line">    <span class="attr">steps:</span></span><br><span class="line">      <span class="bullet">-</span> <span class="attr">name:</span> <span class="string">发布</span> <span class="string">readme.md</span> <span class="string">文件</span></span><br><span class="line">        <span class="attr">id:</span> <span class="string">new_release</span></span><br><span class="line">        <span class="attr">uses:</span> <span class="string">softprops/action-gh-release@v2.0.8</span></span><br><span class="line">        <span class="attr">with:</span></span><br><span class="line">          <span class="attr">token:</span> <span class="string">$&#123;&#123;</span> <span class="string">secrets.LINUX_RELEASE_PERSONAL_TOKEN</span> <span class="string">&#125;&#125;</span></span><br><span class="line">          <span class="attr">name:</span> <span class="string">release-latest</span></span><br><span class="line">          <span class="attr">make_latest:</span> <span class="literal">true</span></span><br><span class="line">          <span class="attr">files:</span> <span class="string">|</span></span><br><span class="line"><span class="string">            readme.md</span></span><br><span class="line"><span class="string">            helloworld_demo.out</span></span><br></pre></td></tr></table></figure>

<p>这个action是在自动打tag的时候将文件发布，例如：</p>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/02%E5%BC%80%E5%8F%91%E5%B7%A5%E5%85%B7/05GithubActions/LV02-GitHubActions-02-%E5%B7%A5%E4%BD%9C%E6%B5%81%E7%A8%8B%E8%AF%AD%E6%B3%95/img/image-20241227161703506.png" alt="image-20241227161703506"  />

<p>这个action的仓库在<a target="_blank" rel="noopener" href="https://github.com/softprops/action-gh-release">GitHub - softprops&#x2F;action-gh-release: 📦 GitHub Action for creating GitHub Releases</a>。里面有对应的使用说明，这里就不再详细说了。</p>
<blockquote>
<p>参考资料：</p>
<p>【1】<a target="_blank" rel="noopener" href="https://www.ruanyifeng.com/blog/2019/09/getting-started-with-github-actions.html">GitHub Actions 入门教程 - 阮一峰的网络日志</a></p>
<p>【2】<a target="_blank" rel="noopener" href="https://githubdocs.cn/en/actions/writing-workflows/workflow-syntax-for-github-actions">GitHub Actions 工作流程语法 - GitHub 文档 - GitHub 文档</a></p>
<p>【3】<a target="_blank" rel="noopener" href="https://www.ruanyifeng.com/blog/2016/07/yaml.html">YAML 语言教程 - 阮一峰的网络日志</a></p>
<p>【4】<a target="_blank" rel="noopener" href="https://yaml.org/spec/1.2.2/">YAML Ain’t Markup Language (YAML™) revision 1.2.2</a></p>
<p>【5】<a target="_blank" rel="noopener" href="https://githubdocs.cn/en/actions/guides">GitHub Actions 指南 - GitHub 文档 - GitHub 文档</a></p>
</blockquote>

    </div>

    
    
    

    <footer class="post-footer">




    <div>
        
            <div style="text-align:center;color: #ccc;font-size:14px;">
            ----------本文结束
            <i class="fas fa-fan fa-spin" style="color: #FF1493; font-size: 1rem"></i>
            感谢您的阅读----------
            </div>
        
    </div>





  
  <div class="my_post_copyright"> 
    <p><span>文章标题:</span><a href="/post/6476912c.html">LV02-GitHubActions-02-工作流程语法</a></p>
    <p><span>文章作者:</span><a href="/" title="欢迎访问 《苏木》 的学习笔记">苏木</a></p>
    <p><span>发布时间:</span>2024年12月28日 - 09:54</p>
    <p><span>最后更新:</span>2025年06月14日 - 00:25</p>
    <p><span>原始链接:</span><a href="/post/6476912c.html" title="LV02-GitHubActions-02-工作流程语法">https://sumumm.github.io/post/6476912c.html</a></p>
    <p><span>许可协议:</span><i class="fab fa-creative-commons"></i> <a rel="license" href= "https://creativecommons.org/licenses/by-nc-nd/4.0/" target="_blank" title="Attribution-NonCommercial-NoDerivatives 4.0 International (CC BY-NC-ND 4.0)">署名-非商业性使用-禁止演绎 4.0 国际</a> 转载请保留原文链接及作者。</p>  
  </div>
  


          <div class="post-tags">
              <a href="/tags/GithubActions/" rel="tag"><i class="fa fa-tag"></i> GithubActions</a>
          </div>

        

          <div class="post-nav">
            <div class="post-nav-item">
                <a href="/post/9c9b496e.html" rel="prev" title="LV03-GitHubActions-01-GithubPages的自动发布">
                  <i class="fa fa-angle-left"></i> LV03-GitHubActions-01-GithubPages的自动发布
                </a>
            </div>
            <div class="post-nav-item">
                <a href="/post/cae87acd.html" rel="next" title="LV02-GitHubActions-01-了解GitHubActions">
                  LV02-GitHubActions-01-了解GitHubActions <i class="fa fa-angle-right"></i>
                </a>
            </div>
          </div>
    </footer>
  </article>
</div>






</div>
  </main>

  <footer class="footer">
    <div class="footer-inner">

  <div class="copyright">
    &copy; 2017 – 
    <span itemprop="copyrightYear">2025</span>
    <span class="with-love">
      <i class="fa fa-heart"></i>
    </span>
    <span class="author" itemprop="copyrightHolder">苏木</span>
  </div>
<div class="wordcount">
  <span class="post-meta-item">
    <span class="post-meta-item-icon">
      <i class="fa fa-chart-line"></i>
    </span>
      <span>站点总字数：</span>
    <span title="站点总字数">3.7m</span>
  </span>
  <span class="post-meta-item">
    <span class="post-meta-item-icon">
      <i class="fa fa-coffee"></i>
    </span>
      <span>站点阅读时长 &asymp;</span>
    <span title="站点阅读时长">225:26</span>
  </span>
</div>




    <span id="sitetime"></span>
    <script defer language=javascript>
        function siteTime()
        {
            window.setTimeout("siteTime()", 1000);
            var seconds = 1000;
            var minutes = seconds * 60;
            var hours = minutes * 60;
            var days = hours * 24;
            var years = days * 365;
            var today = new Date();
            var todayYear = today.getFullYear();
            var todayMonth = today.getMonth()+1;
            var todayDate = today.getDate();
            var todayHour = today.getHours();
            var todayMinute = today.getMinutes();
            var todaySecond = today.getSeconds();
            /*==================================================
            Date.UTC() -- 返回date对象距世界标准时间(UTC)1970年1月1日午夜之间的毫秒数(时间戳)
            year        - 作为date对象的年份，为4位年份值
            month       - 0-11之间的整数，做为date对象的月份
            day         - 1-31之间的整数，做为date对象的天数
            hours       - 0(午夜24点)-23之间的整数，做为date对象的小时数
            minutes     - 0-59之间的整数，做为date对象的分钟数
            seconds     - 0-59之间的整数，做为date对象的秒数
            microseconds - 0-999之间的整数，做为date对象的毫秒数
            ==================================================*/
            var t1 = Date.UTC(2017, 
                              5, 
                              19, 
                              0, 
                              0, 
                              0); //北京时间
            var t2 = Date.UTC(todayYear,todayMonth,todayDate,todayHour,todayMinute,todaySecond);
            var diff = t2-t1;
            var diffYears = Math.floor(diff/years);
            var diffDays = Math.floor((diff/days)-diffYears*365);
            var diffHours = Math.floor((diff-(diffYears*365+diffDays)*days)/hours);
            var diffMinutes = Math.floor((diff-(diffYears*365+diffDays)*days-diffHours*hours)/minutes);
            var diffSeconds = Math.floor((diff-(diffYears*365+diffDays)*days-diffHours*hours-diffMinutes*minutes)/seconds);
            document.getElementById("sitetime").innerHTML="已在这里 "+diffYears+" 年 "+diffDays+" 天 "+diffHours+" 小时 "+diffMinutes+" 分钟 "+diffSeconds+" 秒";
        }
        siteTime();
    </script>



    </div>
  </footer>

  
  <div class="back-to-top" role="button" aria-label="返回顶部">
    <i class="fa fa-arrow-up fa-lg"></i>
    <span>0%</span>
  </div>
  <div class="reading-progress-bar"></div>

<noscript>
  <div class="noscript-warning">Theme NexT works best with JavaScript enabled</div>
</noscript>


  
  <script src="https://cdnjs.cloudflare.com/ajax/libs/animejs/3.2.1/anime.min.js" integrity="sha256-XL2inqUJaslATFnHdJOi9GfQ60on8Wx1C2H8DYiN1xY=" crossorigin="anonymous"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/next-theme-pjax/0.6.0/pjax.min.js" integrity="sha256-vxLn1tSKWD4dqbMRyv940UYw4sXgMtYcK6reefzZrao=" crossorigin="anonymous"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/fancyapps-ui/5.0.28/fancybox/fancybox.umd.js" integrity="sha256-ytMJGN3toR+a84u7g7NuHm91VIR06Q41kMWDr2pq7Zo=" crossorigin="anonymous"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/lozad.js/1.16.0/lozad.min.js" integrity="sha256-mOFREFhqmHeQbXpK2lp4nA3qooVgACfh88fpJftLBbc=" crossorigin="anonymous"></script>
<script src="/js/comments.js"></script><script src="/js/utils.js"></script><script src="/js/motion.js"></script><script src="/js/next-boot.js"></script><script src="/js/pjax.js"></script>

  <script src="https://cdnjs.cloudflare.com/ajax/libs/hexo-generator-searchdb/1.4.1/search.js" integrity="sha256-1kfA5uHPf65M5cphT2dvymhkuyHPQp5A53EGZOnOLmc=" crossorigin="anonymous"></script>
<script src="/js/third-party/search/local-search.js"></script>




  <script src="/js/third-party/fancybox.js"></script>

  <script src="/js/third-party/pace.js"></script>


  




  

  <script class="next-config" data-name="enableMath" type="application/json">true</script><script class="next-config" data-name="mathjax" type="application/json">{"enable":true,"tags":"none","js":{"url":"https://cdnjs.cloudflare.com/ajax/libs/mathjax/3.2.2/es5/tex-mml-chtml.js","integrity":"sha256-MASABpB4tYktI2Oitl4t+78w/lyA+D7b/s9GEP0JOGI="}}</script>
<script src="/js/third-party/math/mathjax.js"></script>


 
        <div id="click-show-text"
            data-mobile = false
            data-text = 富强,民主,文明,和谐,自由,平等,公正,法制,爱国,敬业,诚信,友善
            data-fontsize = 15px
            data-random= false>
        </div>
       

      
        <script async src=https://cdn.jsdelivr.net/npm/hexo-next-mouse-effect@latest/click/showText.js></script>
      

      
    




    <script async src="/js/fancybox_param.js"></script>





<!-- APlayer本体 -->



</body>
</html>
